package com.example.databindingdemo;

import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import com.example.databindingdemo.databinding.ActivityMainBinding;
import com.example.databindingdemo.model.Book;

public class MainActivity extends AppCompatActivity {

    private ActivityMainBinding mBinding;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = DataBindingUtil.setContentView(this, R.layout.activity_main);

        Book book = new Book("jetpack 高性能编程", "tuyrt7");
        book.rating = 5;

        mBinding.setBook(book);
        mBinding.setEventHandler(new EventHandleListener(this));
        mBinding.setNetworkImage("https://img.alicdn.com/tfs/TB1ju9qXupyVu4jSZFhXXbBpVXa-238-69.png");
        mBinding.setLocalImage(R.mipmap.ic_launcher_round);

        mBinding.setImagePadding(40);
        mBinding.setClickHandler(new ClickHandler());
    }

    public void goLogin(View view) {
        startActivity(new Intent(this, LoginActivity.class));
    }

    public void goRecycler(View view) {
        startActivity(new Intent(this, RecyclerActivity.class));
    }

    public class ClickHandler {

        public void onClick(View view) {
            mBinding.setImagePadding(180);
        }
    }
}